<html>
	<head>
		<title>
			Agneum's Leader Board
		</title>
	</head>
	<body bgcolor='#44CC44'>
<?php
// http://labby.is-a-geek.com/leaderboard.php

require_once("db.inc.php");
$sql="select quantity from inventory where knownitemsid = '21' and botid = '1' LIMIT 1;";
$result = mysql_query($sql,$db);
while ($myrow = mysql_fetch_row($result))
$silver = $myrow[0];
if($silver == "1337")
{
	$silver = "<flash><font color='blue'>1 3 3 7</flash></font>";
}
$sql="select quantity from inventory where knownitemsid = '85' and botid = '1' LIMIT 1;";
$result = mysql_query($sql,$db);
while ($myrow = mysql_fetch_row($result))
$sulfur = $myrow[0];
if($sulfur == "1337")
{
	$sulfur = "<flash><font color='blue'>1 3 3 7</flash></font>";
}
echo "\t\t<center><table border= '0' valign = 'top'>\n\t\t\t<tr valign='top'>\n\t\t\t\t<th colspan='2'>Agneum's Silver Ore Leader Board<br>Start Date 17 July 2007<br>Current Stock Level: $silver</th><th colspan='2'>Agneum's Sulfur Leader Board<br>Start Date 17 July 2007<br>Current Stock Level: $sulfur</th>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td valign = 'top'>\n\t\t\t\t\t<table border = '1' VALIGN = 'top'>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th colspan='4'>Buy Leader Board</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th>Position</th>\n\t\t\t\t\t\t\t<th>username</th><th>quantity</th><th>Trades</th>\n\t\t\t\t\t\t</tr>\n";
$sql = "SELECT `username` , sum( `quantity` ) , players.guild"
        . " FROM `tradelog`,players"
        . " WHERE `knownitemsid` = '21' AND `botid`='$botid' AND (`action` = 'buy' OR `action` = 'donate') AND lower(players.name) = lower(username)"
        . " GROUP BY `username`"
        . " ORDER BY action, `sum( ``quantity`` )` DESC  ;";
$sql = "SELECT `username` , sum(`quantity` ), count(*) FROM `tradelog`  WHERE `knownitemsid` ='21' AND `botid` = '$botid' AND (`action` = 'buy' OR `action` = 'donate')  GROUP BY `username`  ORDER BY sum( `quantity` ) DESC  ;";
$result = mysql_query($sql,$db);
echo mysql_error();

$i=1;
while ($myrow = mysql_fetch_row($result))
{
	echo "\t\t\t\t\t\t<tr valign = 'top'";
	if($i==1) echo " bgcolor='#CFB52B'";
	if($i==2) echo " bgcolor='#A8A8A8'";
	if($i==3) echo " bgcolor='#A67D3D'";
	echo ">";
	echo "\n\t\t\t\t\t\t\t<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$i";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t\t<td valign = 'top'>";
	if($i<4) echo "<b><center>";
	/*
	$name=intval($myrow[2]);
	$x1=(($name & 4278190080) /(256*256*256));
	$x2=(($name & 16711680) /(256*256));
	$x3=(($name & 65280) /(256));
	$x4=(($name & 255));
	if($x1==0) $x1 = ""; else $x1 = chr($x1);
	if($x2==0) $x2 = ""; else $x2 = chr($x2);
	if($x3==0) $x3 = ""; else $x3 = chr($x3);
	if($x4==0) $x4 = ""; else $x4 = chr($x4);
	$nameY = $x4 . $x3 . $x2 . $x1;
	echo "$myrow[0] $nameY";
	*/
	echo "$myrow[0]";
	if($i<4) echo "</center></b>";
	echo "</td><td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[1]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[2]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "</tr>\n";
	$i++;
}
echo "<tr><td colspan='4'>";
$sql = "SELECT sum(`quantity` ) FROM `tradelog`  WHERE `knownitemsid` ='21' AND `botid` = '$botid' AND (`action` = 'buy' OR `action` = 'donate');";
$result = mysql_query($sql,$db);
while ($myrow = mysql_fetch_row($result))
{
	echo "<center>Total: $myrow[0]</center>";
}
echo "</td></tr>";
echo "\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td valign = 'top'>\n\t\t\t\t\t<table border = '1' VALIGN = 'top'>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th colspan='4'>Sell Leader Board</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th>Position</th>\n\t\t\t\t\t\t\t<th>username</th><th>quantity</th><th>Trades</th>\n\t\t\t\t\t\t</tr>\n";
$sql = "SELECT `username` , sum( `quantity` ),  count(*) FROM `tradelog` WHERE `knownitemsid` = '21' AND `botid`='$botid' AND (`action` = 'sale' OR `action` = 'give')  GROUP BY `username` ORDER BY sum( `quantity` ) DESC  ;";
$result = mysql_query($sql,$db);

$i=1;
while ($myrow = mysql_fetch_row($result))
{
	echo "\t\t\t\t\t\t<tr valign = 'top'";
	if($i==1) echo " bgcolor='#CFB52B'";
	if($i==2) echo " bgcolor='#A8A8A8'";
	if($i==3) echo " bgcolor='#A67D3D'";
	echo ">";
	echo "\n\t\t\t\t\t\t\t<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$i";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t\t<td valign = 'top'>";
	if($i<4) echo "<b><center>";
	/*
	$name=intval($myrow[2]);
	$x1=(($name & 4278190080) /(256*256*256));
	$x2=(($name & 16711680) /(256*256));
	$x3=(($name & 65280) /(256));
	$x4=(($name & 255));
	if($x1==0) $x1 = ""; else $x1 = chr($x1);
	if($x2==0) $x2 = ""; else $x2 = chr($x2);
	if($x3==0) $x3 = ""; else $x3 = chr($x3);
	if($x4==0) $x4 = ""; else $x4 = chr($x4);
	$nameY = $x4 . $x3 . $x2 . $x1;
	echo "$myrow[0] $nameY";
	*/
	echo "$myrow[0]";
	if($i<4) echo "</center></b>";
	echo "</td><td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[1]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[2]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "</tr>\n";
	$i++;
}
echo "<tr><td colspan='4'>";
$sql = "SELECT sum(`quantity` ) FROM `tradelog`  WHERE `knownitemsid` ='21' AND `botid` = '$botid' AND (`action` = 'sale' OR `action` = 'give');";
$result = mysql_query($sql,$db);
while ($myrow = mysql_fetch_row($result))
{
	echo "<center>Total: $myrow[0]</center>";
}
echo "</td></tr>";
echo "\t\t\t\t\t</table>\n";

// ***************************************************************

echo "\t\t</td><td valign='top'><cen1ter><table border= '1' valign = 'top'>\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th colspan='4'  valign = 'top'>Buy Leader Board</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th>Position</th>\n\t\t\t\t\t\t\t<th>username</th><th>quantity</th><th>Trades</th>\n\t\t\t\t\t\t</tr>\n";
$sql = "SELECT `username` , sum(`quantity` ), count(*) FROM `tradelog`  WHERE `knownitemsid` ='85' AND `botid` = '$botid' AND (`action` = 'buy' OR `action` = 'donate')  GROUP BY `username`  ORDER BY sum( `quantity` ) DESC  ;";
$result = mysql_query($sql,$db);

$i=1;
while ($myrow = mysql_fetch_row($result))
{
	echo "\t\t\t\t\t\t<tr valign = 'top'";
	if($i==1) echo " bgcolor='#CFB52B'";
	if($i==2) echo " bgcolor='#A8A8A8'";
	if($i==3) echo " bgcolor='#A67D3D'";
	echo ">";
	echo "\n\t\t\t\t\t\t\t<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$i";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t\t<td valign = 'top'>";
	if($i<4) echo "<b><center>";
	/*
	$name=intval($myrow[2]);
	$x1=(($name & 4278190080) /(256*256*256));
	$x2=(($name & 16711680) /(256*256));
	$x3=(($name & 65280) /(256));
	$x4=(($name & 255));
	if($x1==0) $x1 = ""; else $x1 = chr($x1);
	if($x2==0) $x2 = ""; else $x2 = chr($x2);
	if($x3==0) $x3 = ""; else $x3 = chr($x3);
	if($x4==0) $x4 = ""; else $x4 = chr($x4);
	$nameY = $x4 . $x3 . $x2 . $x1;
	echo "$myrow[0] $nameY";
	*/
	echo "$myrow[0]";
	if($i<4) echo "</center></b>";
	echo "</td><td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[1]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[2]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "</tr>\n";
	$i++;
}
echo "<tr><td colspan='4'>";
$sql = "SELECT sum(`quantity` ) FROM `tradelog`  WHERE `knownitemsid` ='85' AND `botid` = '$botid' AND (`action` = 'buy' OR `action` = 'donate');";
$result = mysql_query($sql,$db);
while ($myrow = mysql_fetch_row($result))
{
	echo "<center>Total: $myrow[0]</center>";
}
echo "</td></tr>";
echo "\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td valign = 'top'>\n\t\t\t\t\t<table border = '1' VALIGN = 'top'>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th colspan='4'>Sell Leader Board</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr valign = 'top'>\n\t\t\t\t\t\t\t<th>Position</th>\n\t\t\t\t\t\t\t<th>username</th><th>quantity</th><th>Trades</th>\n\t\t\t\t\t\t</tr>\n";
$sql = "SELECT `username` , sum( `quantity` ), count(*) FROM `tradelog` WHERE `knownitemsid` = '85' AND `botid`='$botid' AND (`action` = 'sale' OR `action` = 'give')  GROUP BY `username` ORDER BY sum( `quantity` ) DESC  ;";
$result = mysql_query($sql,$db);

$i=1;
while ($myrow = mysql_fetch_row($result))
{
	echo "\t\t\t\t\t\t<tr valign = 'top'";
	if($i==1) echo " bgcolor='#CFB52B'";
	if($i==2) echo " bgcolor='#A8A8A8'";
	if($i==3) echo " bgcolor='#A67D3D'";
	echo ">";
	echo "\n\t\t\t\t\t\t\t<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$i";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t\t<td valign = 'top'>";
	if($i<4) echo "<b><center>";
	/*
	$name=intval($myrow[2]);
	$x1=(($name & 4278190080) /(256*256*256));
	$x2=(($name & 16711680) /(256*256));
	$x3=(($name & 65280) /(256));
	$x4=(($name & 255));
	if($x1==0) $x1 = ""; else $x1 = chr($x1);
	if($x2==0) $x2 = ""; else $x2 = chr($x2);
	if($x3==0) $x3 = ""; else $x3 = chr($x3);
	if($x4==0) $x4 = ""; else $x4 = chr($x4);
	$nameY = $x4 . $x3 . $x2 . $x1;
	echo "$myrow[0] $nameY";
	*/
	echo "$myrow[0]";
	if($i<4) echo "</center></b>";
	echo "</td><td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[1]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "<td valign = 'top' align='right'>";
	if($i<4) echo "<b><center>";
	echo "$myrow[2]";
	if($i<4) echo "</center></b>";
	echo "</td>\n\t\t\t\t\t\t";
	echo "</tr>\n";
	$i++;
}
echo "<tr><td colspan='4'>";
$sql = "SELECT sum(`quantity` ) FROM `tradelog`  WHERE `knownitemsid` ='85' AND `botid` = '$botid' AND (`action` = 'sale' OR `action` = 'give');";
$result = mysql_query($sql,$db);
while ($myrow = mysql_fetch_row($result))
{
	echo "<center>Total: $myrow[0]</center>";
}
echo "</td></tr>";
echo "\t\t\t\t\t</table>\n";

echo "\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table></center>\n\t</body>\n</html>";
mysql_close($db);
?>